package master;

import master.EmployerDao;
import master.EmployerDaoImpl;
import master.Employer;
import user.DBUtil;

import javax.swing.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class EmployerService {
    private EmployerDao employerDao = new EmployerDaoImpl();

    public List<Employer> getAllEmployers() {
        Connection conn = null;
        try {
            conn = DBUtil.getConnection();
            return employerDao.getAllEmployers(conn);
        } catch (SQLException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "员工数据加载失败: "+e.getMessage());
            return null;
        } finally {
            DBUtil.closeConnection(conn);
        }
    }

    public boolean addEmployer(Employer employer) {
        Connection conn = null;
        try {
            conn = DBUtil.getConnection();
            return employerDao.addEmployer(conn, employer) > 0;
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        } finally {
            DBUtil.closeConnection(conn);
        }
    }
}
